package com.free.fs.controller;

import com.free.fs.controller.util.Result;
import com.free.fs.model.BlogData;
import com.free.fs.model.Summary;
import com.free.fs.service.BlogDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("BlogData")
public class BlogDataController {
    @Autowired
    BlogDataService blogDataService;

    @GetMapping
    Result getAll(){

        return new Result(true,blogDataService.list());
    }

    @GetMapping("/{id}")
    Result getById(@PathVariable Integer id){
        return new Result(true,blogDataService.getById(id));
    }

    @PostMapping
    Result save(@RequestBody BlogData blogdata) throws IOException {
//        System.out.print(blogdata.toString()+"进入Post");
//        System.out.print(blogdata.getName());
        boolean flag=blogDataService.save(blogdata);
        return new Result(flag,flag?"添加成功":"添加失败");
    }

    @PutMapping
    Result update(@RequestBody BlogData blogdata){
        return new Result(blogDataService.updateById(blogdata));
    }

    @DeleteMapping("/{id}")
    Result delete(@PathVariable Integer id){
        return new Result(blogDataService.removeById(id));
    }
}
